﻿<%@ WebHandler Language="C#" Class="CollectBusinessData" %>

using System;
using System.Web;
using System.Data;
using Chenxin.Lib.Utility;
using System.Collections.Generic;

public class CollectBusinessData : AjaxHandlerBase
{
    override public void RequestProcess(HttpContext context)
    {
        context.Response.AddHeader("pragma", "no-cache");
        context.Response.AddHeader("cache-control", "");
        context.Response.CacheControl = "no-cache";

        string op = context.Request.Params["op"];
        string strRet = string.Empty;
        try
        {
            switch (op)
            {
                case "Search":
                    strRet = SearchCollectionData(context);
                    break;
                case "getdetailgrid":
                    strRet = GetDetailList(context);
                    break;
            }
            context.Response.Write(strRet);
        }
        catch (Exception ex)
        {
            strRet = retExecResult(Constants.ExecResult.Error, ex.Message, "");
            context.Response.Write(strRet);
        }
    }

    //营业数据汇总
    private string SearchCollectionData(HttpContext context)
    {
        string strRet = string.Empty;
        string strParam = string.Empty;
        string ParentType = string.Empty;
        string ParentId = string.Empty;
        int NodeType = 0;
        Guid ObjectId = Guid.Empty;
        
        string strCollNm = string.Empty;
        string strSumNm = "组数";
        string strAverageNm = "组均";
        
        //开始日期
        DateTime StartDate = new DateTime(2000, 1, 1);
        //结束日期
        DateTime EndDate = new DateTime(3000, 1, 1);

        if (context.Request.Params["StartDate"] == null && context.Request.Params["EndDate"] == null)
        {
            StartDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
            EndDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59);
        }
        else
        {
            //检索开始日期
            strParam = context.Request.Params["StartDate"];
            if (!string.IsNullOrEmpty(strParam))
            {
                StartDate = DateTime.Parse(strParam);
            }
            
            //检索结束日期
            strParam = context.Request.Params["EndDate"];
            if (!string.IsNullOrEmpty(strParam))
            {
                EndDate = DateTime.Parse(strParam + " 23:59:59");
            }
        }

        ParentType = context.Request.Params["ParentType"];
        ParentId = context.Request.Params["ParentId"];

        //显示子节点数据
        if (!string.IsNullOrEmpty(ParentType))
        {
            if (ParentType.Equals("0"))
            {
                NodeType = 10;
                strCollNm = "公司";
            }
            else if (ParentType.Equals("10"))
            {
                NodeType = 20;
                strCollNm = "商圈";
            }
            else if (ParentType.Equals("20"))
            {
                NodeType = 30;
                strCollNm = "部门";
            }
            else if (ParentType.Equals("30") || ParentType.Equals("25"))
            {
                NodeType = 40;
                strCollNm = "人员";
            }

            ObjectId = new Guid(ParentId);
        }
        //初始显示
        else
        {
            //权限判断
            //全权限
            if (CurrentUserInfo.ContainsPermit(Constants.Permit_ViewAllArchivement))
            {
                NodeType = 0;
                strCollNm = "城市";
            }
            //城市权限
            else if (CurrentUserInfo.ContainsPermit(Constants.Permit_ViewCityArchivement))
            {
                NodeType = 10;
                ObjectId = CurrentUserInfo.CityId;
                strCollNm = "公司";
            }
            //公司权限
            else if (CurrentUserInfo.ContainsPermit(Constants.Permit_ViewCompanyArchivement))
            {
                NodeType = 20;
                ObjectId = CurrentUserInfo.CompanyId;
                strCollNm = "商圈";
            }
            //部门权限
            else if (CurrentUserInfo.ContainsPermit(Constants.Permit_ViewDepartArchivement))
            {
                NodeType = 25;
                ObjectId = CurrentUserInfo.UserId;
                strCollNm = "部门";
            }
            //个人权限
            else
            {
                NodeType = 50;
                ObjectId = CurrentUserInfo.UserId;
                strCollNm = "个人";
            }
        }
        
        //营业动态业务类
        Chenxin.Lib.House.BLL.House_DataCollection bllColl = new Chenxin.Lib.House.BLL.House_DataCollection();
        //汇总数据
        System.Data.DataSet dsColl = bllColl.GetCollection(NodeType, ObjectId, StartDate, EndDate);

        System.Text.StringBuilder strHtml = new System.Text.StringBuilder();
        System.Text.StringBuilder strHead = new System.Text.StringBuilder();

        strHead.Append("ChildId:{head:'ObjectId',width:40,sortable:true,create:false},");
        strHead.Append("ChildName:{head:'" + strCollNm + "',width:100,sortable:true,renderer:function(value,field,row){");
        strHead.Append("	return \'<a class=\"childname\" title=\"\'+row.ChildName+\'\" n=\"" + (NodeType) + "\" p=\"" + (ObjectId) + "\"  i=\"\'+row.ChildId+\'\" >\'+value+\'</a>\';}},");
        if (NodeType < 25)
        {
            strHead.Append("GrandsonCnt:{head:'" + strSumNm + "',width:80,sortable:true},");
        }
        else
        {
            strHead.Append("GrandsonCnt:{head:'" + strSumNm + "',width:80,sortable:true,create:false},");
        }

        strHead.Append("House:{");/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
        strHead.Append("      head:'房源',");
        if (NodeType < 25)
        {
            strHead.Append("      width:384,");
        }
        else
        {
            strHead.Append("      width:240,");
        }
        strHead.Append("      items:{");
        strHead.Append("            CNT_HOUSE_SALE:{head:'买卖',width:80,sortable:true,renderer:function(value,field,row){ return \'<a class=\"number\" title=\"\'+value+\'\" n=\""+NodeType+"\" i=\"\'+row.ChildId+\'\" t=\"house_sale\" d=\"\'+row.ChildName+\'\">\'+value+ \'</a>\'}},");
        strHead.Append("            CNT_HOUSE_RENT:{head:'租赁',width:80,sortable:true,renderer:function(value,field,row){ return \'<a class=\"number\" title=\"\'+value+\'\" n=\"" + NodeType + "\" i=\"\'+row.ChildId+\'\" t=\"house_rent\" d=\"\'+row.ChildName+\'\">\'+value+ \'</a>\'}},"); /*********房源********/
        if (NodeType < 25)
        {
            strHead.Append("            CNT_HOUSE_TOTAL:{head:'合计',width:80,sortable:true,renderer:function(value,field,row){ return \'<a class=\"number\" title=\"\'+value+\'\" n=\"" + NodeType + "\" i=\"\'+row.ChildId+\'\" t=\"house_count\" d=\"\'+row.ChildName+\'\">\'+value+ \'</a>\'}},");

            strHead.Append("            AVG_HOUSE:{head:'" + strAverageNm + "',width:80,sortable:true,inTotal:false,},");
            strHead.Append("            RANK_HOUSE:{head:'" + strAverageNm + "排名',width:64,sortable:true,inTotal:false,style:'background-color:#ffffcc'}");
        }
        else
        {
            strHead.Append("            CNT_HOUSE_TOTAL:{head:'合计',width:80,sortable:true,style:'background-color:#ffffcc',renderer:function(value,field,row){ return \'<a class=\"number\" title=\"\'+value+\'\" n=\"" + NodeType + "\" i=\"\'+row.ChildId+\'\" t=\"house_count\" d=\"\'+row.ChildName+\'\">\'+value+ \'</a>\'}},");
       
            strHead.Append("            AVG_HOUSE:{head:'" + strAverageNm + "',width:40,sortable:true,inTotal:false,create:false},");
            strHead.Append("            RANK_HOUSE:{head:'" + strAverageNm + "排名',width:64,sortable:true,inTotal:false,create:false}");
        }
        strHead.Append("      }");
        strHead.Append("},");/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/

        strHead.Append("HouseTrace:{");/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
        strHead.Append("      head:'房源跟盘',");
        if (NodeType < 25)
        {
            strHead.Append("      width:384,");
        }
        else
        {
            strHead.Append("      width:240,");
        }
        strHead.Append("      items:{");
        strHead.Append("       CNT_HOUSETRACE_SALE:{head:'买卖',width:80,sortable:true,renderer:function(value,field,row){ return \'<a class=\"number\" title=\"\'+value+\'\" n=\"" + NodeType + "\" p=\"" + (ObjectId) + "\" i=\"\'+row.ChildId+\'\" t=\"housetrace_sale\" d=\"\'+row.ChildName+\'\">\'+value+ \'</a>\'}},");
        strHead.Append("       CNT_HOUSETRACE_RENT:{head:'租赁',width:80,sortable:true,renderer:function(value,field,row){ return \'<a class=\"number\" title=\"\'+value+\'\" n=\"" + NodeType + "\" p=\"" + (ObjectId) + "\" i=\"\'+row.ChildId+\'\" t=\"housetrace_rent\" d=\"\'+row.ChildName+\'\">\'+value+ \'</a>\'}},");/*********房源跟单********/
        if (NodeType < 25)
        {
            strHead.Append("       CNT_HOUSETRACE_TOTAL:{head:'合计',width:80,sortable:true,renderer:function(value,field,row){ return \'<a class=\"number\" title=\"\'+value+\'\" n=\"" + NodeType + "\" p=\"" + (ObjectId) + "\" i=\"\'+row.ChildId+\'\" t=\"housetrace_count\" d=\"\'+row.ChildName+\'\">\'+value+ \'</a>\'}},");
            strHead.Append("       AVG_HOUSETRACE:{head:'" + strAverageNm + "',width:80,sortable:true,inTotal:false},");
            strHead.Append("       RANK_HOUSETRACE:{head:'" + strAverageNm + "排名',width:64,sortable:true,inTotal:false,style:'background-color:#ffffcc'}");
        }
        else
        {
            strHead.Append("       CNT_HOUSETRACE_TOTAL:{head:'合计',width:80,sortable:true,style:'background-color:#ffffcc',renderer:function(value,field,row){ return \'<a class=\"number\" title=\"\'+value+\'\" n=\"" + NodeType + "\" p=\"" + (ObjectId) + "\" i=\"\'+row.ChildId+\'\" t=\"housetrace_count\" d=\"\'+row.ChildName+\'\">\'+value+ \'</a>\'}},");
            strHead.Append("       AVG_HOUSETRACE:{head:'" + strAverageNm + "',width:80,sortable:true,inTotal:false,create:false},");
            strHead.Append("       RANK_HOUSETRACE:{head:'" + strAverageNm + "排名',width:64,sortable:true,inTotal:false,create:false}");
        }
        strHead.Append("      }");
        strHead.Append("},");/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/

        strHead.Append("Demand:{");/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
        strHead.Append("      head:'客户需求',");
        if (NodeType < 25)
        {
            strHead.Append("      width:384,");
        }
        else
        {
            strHead.Append("      width:240,");
        }
        strHead.Append("      items:{");
        strHead.Append("            CNT_DEMAND_SALE:{head:'买卖',width:80,sortable:true,renderer:function(value,field,row){ return \'<a class=\"number\" title=\"\'+value+\'\" n=\"" + NodeType + "\" i=\"\'+row.ChildId+\'\" t=\"customer_sale\" d=\"\'+row.ChildName+\'\">\'+value+ \'</a>\'}},");
        strHead.Append("            CNT_DEMAND_RENT:{head:'租赁',width:80,sortable:true,renderer:function(value,field,row){ return \'<a class=\"number\" title=\"\'+value+\'\" n=\"" + NodeType + "\" i=\"\'+row.ChildId+\'\" t=\"customer_rent\" d=\"\'+row.ChildName+\'\">\'+value+ \'</a>\'}},");/*********客户需求********/
        if (NodeType < 25)
        {
            strHead.Append("            CNT_DEMAND_TOTAL:{head:'合计',width:80,sortable:true,renderer:function(value,field,row){ return \'<a class=\"number\" title=\"\'+value+\'\" n=\"" + NodeType + "\" i=\"\'+row.ChildId+\'\" t=\"customer_count\" d=\"\'+row.ChildName+\'\">\'+value+ \'</a>\'}},");
            strHead.Append("            AVG_DEMAND:{head:'" + strAverageNm + "',width:80,sortable:true,inTotal:false},");
            strHead.Append("            RANK_DEMAND:{head:'" + strAverageNm + "排名',width:64,sortable:true,inTotal:false,style:'background-color:#ffffcc'}");
        }
        else
        {
            strHead.Append("            CNT_DEMAND_TOTAL:{head:'合计',width:80,sortable:true,style:'background-color:#ffffcc',renderer:function(value,field,row){ return \'<a class=\"number\" title=\"\'+value+\'\" n=\"" + NodeType + "\" i=\"\'+row.ChildId+\'\" t=\"customer_count\" d=\"\'+row.ChildName+\'\">\'+value+ \'</a>\'}},");
            strHead.Append("            AVG_DEMAND:{head:'" + strAverageNm + "',width:80,sortable:true,inTotal:false,create:false},");
            strHead.Append("            RANK_DEMAND:{head:'" + strAverageNm + "排名',width:64,sortable:true,inTotal:false,create:false}");
        }
        strHead.Append("      }");
        strHead.Append("},");/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/

        strHead.Append("DemandTrace:{");/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
        strHead.Append("      head:'客需跟盘',");
        if (NodeType < 25)
        {
            strHead.Append("      width:384,");
        }
        else
        {
            strHead.Append("      width:240,");
        }
        strHead.Append("      items:{");
        strHead.Append("            CNT_DEMANDTRACE_SALE:{head:'买卖',width:80,sortable:true,renderer:function(value,field,row){ return \'<a class=\"number\" title=\"\'+value+\'\" n=\"" + NodeType + "\" p=\"" + (ObjectId) + "\" i=\"\'+row.ChildId+\'\" t=\"customertrace_sale\" d=\"\'+row.ChildName+\'\">\'+value+ \'</a>\'}},");
        strHead.Append("            CNT_DEMANDTRACE_RENT:{head:'租赁',width:80,sortable:true,renderer:function(value,field,row){ return \'<a class=\"number\" title=\"\'+value+\'\" n=\"" + NodeType + "\" p=\"" + (ObjectId) + "\" i=\"\'+row.ChildId+\'\" t=\"customertrace_rent\" d=\"\'+row.ChildName+\'\">\'+value+ \'</a>\'}},");/*********客户需求********/
        if (NodeType < 25)
        {
            strHead.Append("            CNT_DEMANDTRACE_TOTAL:{head:'合计',width:80,sortable:true,renderer:function(value,field,row){ return \'<a class=\"number\" title=\"\'+value+\'\" p=\"" + (ObjectId) + "\" n=\"" + NodeType + "\" i=\"\'+row.ChildId+\'\" t=\"customertrace_count\" d=\"\'+row.ChildName+\'\">\'+value+ \'</a>\'}},");
            strHead.Append("            AVG_DEMANDTRACE:{head:'" + strAverageNm + "',width:80,inTotal:false,sortable:true},");
            strHead.Append("            RANK_DEMANDTRACE:{head:'" + strAverageNm + "排名',width:64,sortable:true,inTotal:false,style:'background-color:#ffffcc'}");
        }
        else
        {
            strHead.Append("            CNT_DEMANDTRACE_TOTAL:{head:'合计',width:80,sortable:true,style:'background-color:#ffffcc',renderer:function(value,field,row){ return \'<a class=\"number\" title=\"\'+value+\'\" n=\"" + NodeType + "\" p=\"" + (ObjectId) + "\" i=\"\'+row.ChildId+\'\" t=\"customertrace_count\" d=\"\'+row.ChildName+\'\">\'+value+ \'</a>\'}},");
            strHead.Append("            AVG_DEMANDTRACE:{head:'" + strAverageNm + "',width:80,inTotal:false,sortable:true,create:false},");
            strHead.Append("            RANK_DEMANDTRACE:{head:'" + strAverageNm + "排名',width:64,inTotal:false,sortable:true,create:false}");
        }
        strHead.Append("      }");
        strHead.Append("},");/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/

        strHead.Append("ViewHouse:{");/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
        strHead.Append("      head:'带看',");
        if (NodeType < 25)
        {
            strHead.Append("      width:224,");
        }
        else
        {
            strHead.Append("      width:80,");
        }
        strHead.Append("      items:{");
        if (NodeType < 25)
        {
            strHead.Append("            CNT_VIEWHOUSE:{head:'合计',width:80,sortable:true,renderer:function(value,field,row){ return \'<a class=\"number\" title=\"\'+value+\'\" n=\"" + NodeType + "\" i=\"\'+row.ChildId+\'\" t=\"viewhouse_count\" d=\"\'+row.ChildName+\'\">\'+value+ \'</a>\'}},");/*********带看********/
            strHead.Append("            AVG_VIEWHOUSE:{head:'" + strAverageNm + "',width:80,inTotal:false,sortable:true},");
            strHead.Append("            RANK_VIEWHOUSE:{head:'" + strAverageNm + "排名',width:64,sortable:true,inTotal:false,style:'background-color:#ffffcc'}");
        }
        else
        {
            strHead.Append("            CNT_VIEWHOUSE:{head:'合计',width:80,sortable:true,style:'background-color:#ffffcc',renderer:function(value,field,row){ return \'<a class=\"number\" title=\"\'+value+\'\" n=\"" + NodeType + "\" i=\"\'+row.ChildId+\'\" t=\"viewhouse_count\" d=\"\'+row.ChildName+\'\">\'+value+ \'</a>\'}},");
            strHead.Append("            AVG_VIEWHOUSE:{head:'" + strAverageNm + "',width:80,inTotal:false,sortable:true,create:false},");
            strHead.Append("            RANK_VIEWHOUSE:{head:'" + strAverageNm + "排名',width:64,inTotal:false,sortable:true,create:false}");
        }
        strHead.Append("      }");
        strHead.Append("}");/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/
        
        strHtml.Append("{");
        strHtml.Append("success:'" + ((int)Constants.ExecResult.Succ).ToString() + "',");
        strHtml.Append("msg:'',");
        strHtml.AppendFormat("data:{{{0},", Chenxin.Lib.Utility.JsonHelp.Convert2Json(dsColl.Tables[0]));
        strHtml.AppendFormat("head:{{{0}}}", strHead.ToString());
        strHtml.AppendFormat(",count:'{0}'", dsColl.Tables[0].Rows.Count);
        strHtml.Append("}");
        strHtml.Append("}");

        strRet = strHtml.ToString();
        
        return strRet;
    }

    private string GetDetailList(HttpContext context)
    {
        string strRet = string.Empty;

        string ListType = context.Request.Params["dtype"];

        switch (ListType)
        {
            //房源
            case "house_sale":
            case "house_rent":
            case "house_count":
                strRet = GetHouseList(context);
                break;
            //客需
            case "customer_sale":
            case "customer_rent":
            case "customer_count":
                strRet = GetDemandList(context);
                break;
            //跟单
            case "housetrace_sale":
            case "housetrace_rent":
            case "housetrace_count":
            case "customertrace_sale":
            case "customertrace_rent":
            case "customertrace_count":
                strRet = GetTraceList(context);
                break;
            //带看
            case "viewhouse_count":
                strRet = GetViewHouseList(context);
                break;
        }
        
        return strRet;
    }

    //房源列表
    private string GetHouseList(HttpContext context)
    {
        string strParam = string.Empty;
        Dictionary<string,string> dicParams = new Dictionary<string,string>();
        int PageIndex = 1; 
        
        if (context.Request.Params["StartDate"] == null && context.Request.Params["EndDate"] == null)
        {
            //检索开始日期
            dicParams.Add("StartDate", DateTime.Now.ToString("yyyy-MM-dd"));
            //检索结束日期
            dicParams.Add("EndDate", DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:59");
        }
        else
        {
            //检索开始日期
            strParam = context.Request.Params["StartDate"];
            if (!string.IsNullOrEmpty(strParam))
            {
                dicParams.Add("StartDate", strParam);
            }
            //检索结束日期
            strParam = context.Request.Params["EndDate"];
            if (!string.IsNullOrEmpty(strParam))
            {
                dicParams.Add("EndDate", strParam + " 23:59:59");
            }
        }

        //当前节点类型
        strParam = context.Request.Params["ParentType"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("ParentType", strParam);
        }

        //当前节点ID
        strParam = context.Request.Params["ParentId"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("ParentId", strParam);
        }

        //当前页码
        strParam = context.Request["pageindex"];
        if (!string.IsNullOrEmpty(strParam))
        {
            PageIndex = Convert.ToInt32(strParam) + 1;
            dicParams.Add("PageIndex", PageIndex.ToString());
        }
        //页步长
        strParam = context.Request["pagesize"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("PageSize", strParam);
        }

        dicParams.Add("dtype", context.Request.Params["dtype"].ToString());

        //排序
        strParam = context.Request["sort"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("sort", strParam);
        }
        
        DataSet dsList = Chenxin.Lib.House.BLL.House_BaseInfo.GetHouseListByParams(dicParams);

        System.Text.StringBuilder strHead = new System.Text.StringBuilder();
        System.Text.StringBuilder strHtml = new System.Text.StringBuilder();
        
        strHead.AppendFormat("Region:{{width:{0},head:'{1}',sortable:true}},", 40, "区域");
        strHead.AppendFormat("Status:{{width:{0},head:'{1}',sortable:true}},", 40, "状态");
        strHead.AppendFormat("Address:{{width:{0},head:'{1}',sortable:true,sortField:'{2}',style:'text-align:left'}},", 170, "楼盘/门号/房号", "Community,BuildingName,Room");
        strHead.AppendFormat("BusinessKind:{{width:{0},head:'{1}',sortable:true}},", 40, "交易");
        strHead.AppendFormat("BuildingArea:{{width:{0},head:'{1}',sortable:true}},", 55, "面积");
        strHead.AppendFormat("SalePrice_U:{{width:{0},head:'{1}',sortable:true}},", 60, "单价(元)");
        strHead.AppendFormat("SalePrice_T:{{width:{0},head:'{1}',sortable:true,sortField:'{2}'}},", 65, "总价", "SalePrice_T,RentPrice");
        strHead.AppendFormat("HouseStyle:{{width:{0},head:'{1}',sortable:true,sortField:'{2}'}},", 40, "房型", "Model_Room,Model_Hall,Model_Toilet");
        strHead.AppendFormat("Floor:{{width:{0},head:'{1}',sortable:true,sortField:'{2}'}},", 50, "楼层", "Cur_Floor");
        strHead.AppendFormat("OprDepart:{{width:{0},head:'{1}',sortable:true}},", 70, "部门");
        strHead.AppendFormat("OprPerson:{{width:{0},head:'{1}',sortable:true}},", 60, "业务员");
        strHead.AppendFormat("Adddate:{{width:{0},head:'{1}',sortable:true}}", 70, "建档时间");

        strHtml.Append("{");
        strHtml.Append("success:'1',");
        strHtml.Append("msg:'',");
        strHtml.AppendFormat("data:{{{0},", Chenxin.Lib.Utility.JsonHelp.Convert2Json(dsList.Tables[0]));
        strHtml.AppendFormat("head:{{{0}}}", strHead.ToString());
        strHtml.AppendFormat(",count:'{0}'", dsList.Tables[1].Rows[0][0]);
        strHtml.Append("}");
        strHtml.Append("}");

        return strHtml.ToString();
    }

    //客需列表
    private string GetDemandList(HttpContext context)
    {
        string strParam = string.Empty;
        Dictionary<string, string> dicParams = new Dictionary<string, string>();
        int PageIndex = 1;

        if (context.Request.Params["StartDate"] == null && context.Request.Params["EndDate"] == null)
        {
            //检索开始日期
            dicParams.Add("StartDate", DateTime.Now.ToString("yyyy-MM-dd"));
            //检索结束日期
            dicParams.Add("EndDate", DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:59");
        }
        else
        {
            //检索开始日期
            strParam = context.Request.Params["StartDate"];
            if (!string.IsNullOrEmpty(strParam))
            {
                dicParams.Add("StartDate", strParam);
            }
            //检索结束日期
            strParam = context.Request.Params["EndDate"];
            if (!string.IsNullOrEmpty(strParam))
            {
                dicParams.Add("EndDate", strParam + " 23:59:59");
            }
        }

        //当前节点类型
        strParam = context.Request.Params["ParentType"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("ParentType", strParam);
        }

        //当前节点ID
        strParam = context.Request.Params["ParentId"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("ParentId", strParam);
        }

        //当前页码
        strParam = context.Request["pageindex"];
        if (!string.IsNullOrEmpty(strParam))
        {
            PageIndex = Convert.ToInt32(strParam) + 1;
            dicParams.Add("PageIndex", PageIndex.ToString());
        }
        //页步长
        strParam = context.Request["pagesize"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("PageSize", strParam);
        }

        dicParams.Add("dtype", context.Request.Params["dtype"].ToString());

        //排序
        strParam = context.Request["sort"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("sort", strParam);
        }
                
        DataSet dsList = Chenxin.Lib.House.BLL.Custom_Info.GetDemandListByParams(dicParams);

        System.Text.StringBuilder strHead = new System.Text.StringBuilder();
        System.Text.StringBuilder strHtml = new System.Text.StringBuilder();

        strHead.AppendFormat("OprDepart:{{width:{0},head:'{1}',sortable:true}},", 100, "门店");
        strHead.AppendFormat("OprPerson:{{width:{0},head:'{1}',sortable:true}},", 80, "业务员");
        strHead.AppendFormat("CustomerName:{{width:{0},head:'{1}',sortable:true}},", 80, "客户姓名");
        strHead.AppendFormat("PubLevel:{{width:{0},head:'{1}',sortable:true}},", 90, "公开级别");
        strHead.AppendFormat("DemandKind:{{width:{0},head:'{1}',sortable:true}},", 70, "需求种类");
        strHead.AppendFormat("DemandType:{{width:{0},head:'{1}',sortable:true}},", 70, "需求类型");
        strHead.AppendFormat("DemandZone:{{width:{0},head:'{1}',sortable:true}},", 120, "需求区域");
        strHead.AppendFormat("DemandArea:{{width:{0},head:'{1}',sortable:true}},", 100, "需求面积");
        strHead.AppendFormat("TotalPrice:{{width:{0},head:'{1}',sortable:true}},", 100, "总(售/租)价");
        strHead.AppendFormat("Catalog:{{width:{0},head:'{1}',sortable:true}},", 40, "类别");
        strHead.AppendFormat("HouseBuyTime:{{width:{0},head:'{1}',sortable:true}},", 120, "需求时间");
        strHead.AppendFormat("HouseUse:{{width:{0},head:'{1}',sortable:true}},", 150, "房屋用途");
        strHead.AppendFormat("Consider:{{width:{0},head:'{1}',sortable:true}},", 150, "考虑因素");
        strHead.AppendFormat("ServiceDemand:{{width:{0},head:'{1}',sortable:true}},", 150, "服务需求");
        strHead.AppendFormat("DemandBuilding:{{width:{0},head:'{1}',sortable:true}},", 120, "物业类型");
        strHead.AppendFormat("SpecialDemand:{{width:{0},head:'{1}',sortable:true}},", 120, "特殊需求");
        strHead.AppendFormat("HouseStyle:{{width:{0},head:'{1}',sortable:true,sortField:'{2}'}},", 70, "房型需求", "DemandStyle_Room,DemandStyle_Hall,DemandStyle_Toilet");
        strHead.AppendFormat("UnitPrice:{{width:{0},head:'{1}',sortable:true}},", 120, "单价");
        strHead.AppendFormat("Fitment:{{width:{0},head:'{1}',sortable:true}},", 120, "装修情况");
        strHead.AppendFormat("ReturnRate:{{width:{0},head:'{1}',sortable:true}},", 120, "期望回报率");
        strHead.AppendFormat("Addtime:{{width:{0},head:'{1}',sortable:true}},", 80, "建档时间");
        strHead.AppendFormat("LastTraceDay:{{width:{0},head:'{1}',sortable:true}},", 120, "跟单时间");
        
        strHtml.Append("{");
        strHtml.Append("success:'1',");
        strHtml.Append("msg:'',");
        strHtml.AppendFormat("data:{{{0},", Chenxin.Lib.Utility.JsonHelp.Convert2Json(dsList.Tables[0]));
        strHtml.AppendFormat("head:{{{0}}}", strHead.ToString());
        strHtml.AppendFormat(",count:'{0}'", dsList.Tables[1].Rows[0][0]);
        strHtml.Append("}");
        strHtml.Append("}");

        return strHtml.ToString();
    }

    //带看
    private string GetViewHouseList(HttpContext context)
    {
        string strParam = string.Empty;
        Dictionary<string, string> dicParams = new Dictionary<string, string>();
        int PageIndex = 1;

        if (context.Request.Params["StartDate"] == null && context.Request.Params["EndDate"] == null)
        {
            //检索开始日期
            dicParams.Add("StartDate", DateTime.Now.ToString("yyyy-MM-dd"));
            //检索结束日期
            dicParams.Add("EndDate", DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:59");
        }
        else
        {
            //检索开始日期
            strParam = context.Request.Params["StartDate"];
            if (!string.IsNullOrEmpty(strParam))
            {
                dicParams.Add("StartDate", strParam);
            }
            //检索结束日期
            strParam = context.Request.Params["EndDate"];
            if (!string.IsNullOrEmpty(strParam))
            {
                dicParams.Add("EndDate", strParam + " 23:59:59");
            }
        }

        //当前节点类型
        strParam = context.Request.Params["ParentType"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("ParentType", strParam);
        }

        //当前节点ID
        strParam = context.Request.Params["ParentId"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("ParentId", strParam);
        }

        //当前页码
        strParam = context.Request["pageindex"];
        if (!string.IsNullOrEmpty(strParam))
        {
            PageIndex = Convert.ToInt32(strParam) + 1;
            dicParams.Add("PageIndex", PageIndex.ToString());
        }
        //页步长
        strParam = context.Request["pagesize"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("PageSize", strParam);
        }

        //排序
        strParam = context.Request["sort"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("sort", strParam);
        }
        
        dicParams.Add("dtype", context.Request.Params["dtype"].ToString());

        DataSet dsList = Chenxin.Lib.House.BLL.Customer_ViewHouseInfo.GetViewHouseListByParams(dicParams);

        System.Text.StringBuilder strHead = new System.Text.StringBuilder();
        System.Text.StringBuilder strHtml = new System.Text.StringBuilder();

        strHead.AppendFormat("CustomerName:{{width:{0},head:'{1}',sortable:true}},", 80, "带看客户");
        strHead.AppendFormat("Reportor:{{width:{0},head:'{1}',sortable:true}},", 140, "带看人");
        strHead.AppendFormat("ReportDepart:{{width:{0},head:'{1}',sortable:true}},", 100, "带看部门");
        strHead.AppendFormat("Operator:{{width:{0},head:'{1}',sortable:true}},", 80, "添加人");
        strHead.AppendFormat("OprDepart:{{width:{0},head:'{1}',sortable:true}},", 100, "添加部门");
        strHead.AppendFormat("ViewTime:{{width:{0},head:'{1}',sortable:true}}", 90, "带看时间");
        
        strHtml.Append("{");
        strHtml.Append("success:'1',");
        strHtml.Append("msg:'',");
        strHtml.AppendFormat("data:{{{0},", Chenxin.Lib.Utility.JsonHelp.Convert2Json(dsList.Tables[0]));
        strHtml.AppendFormat("head:{{{0}}}", strHead.ToString());
        strHtml.AppendFormat(",count:'{0}'", dsList.Tables[1].Rows[0][0]);
        strHtml.Append("}");
        strHtml.Append("}");

        return strHtml.ToString();
    }

    //跟单
    private string GetTraceList(HttpContext context)
    {
        string strParam = string.Empty;
        Dictionary<string, string> dicParams = new Dictionary<string, string>();
        int PageIndex = 1;

        if (context.Request.Params["StartDate"] == null && context.Request.Params["EndDate"] == null)
        {
            //检索开始日期
            dicParams.Add("StartDate", DateTime.Now.ToString("yyyy-MM-dd"));
            //检索结束日期
            dicParams.Add("EndDate", DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:59");
        }
        else
        {
            //检索开始日期
            strParam = context.Request.Params["StartDate"];
            if (!string.IsNullOrEmpty(strParam))
            {
                dicParams.Add("StartDate", strParam);
            }
            //检索结束日期
            strParam = context.Request.Params["EndDate"];
            if (!string.IsNullOrEmpty(strParam))
            {
                dicParams.Add("EndDate", strParam + " 23:59:59");
            }
        }

        //当前节点类型
        strParam = context.Request.Params["ParentType"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("ParentType", strParam);
        }

        //当前节点ID
        strParam = context.Request.Params["ParentId"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("ParentId", strParam);
        }

        //当前页码
        strParam = context.Request["pageindex"];
        if (!string.IsNullOrEmpty(strParam))
        {
            PageIndex = Convert.ToInt32(strParam) + 1;
            dicParams.Add("PageIndex", PageIndex.ToString());
        }
        //页步长
        strParam = context.Request["pagesize"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("PageSize", strParam);
        }

        //排序
        strParam = context.Request["sort"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("sort", strParam);
        }

        //父节点
        strParam = context.Request["FatherId"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("FatherId", strParam);
        }
        
        dicParams.Add("dtype", context.Request.Params["dtype"].ToString());

        DataSet dsList = Chenxin.Lib.House.BLL.House_TraceInfo.GetTraceListByParams(dicParams);

        System.Text.StringBuilder strHead = new System.Text.StringBuilder();
        System.Text.StringBuilder strHtml = new System.Text.StringBuilder();

        if (context.Request.Params["dtype"].Equals("customertrace_sale") ||
            context.Request.Params["dtype"].Equals("customertrace_rent") ||
            context.Request.Params["dtype"].Equals("customertrace_count"))
        {
            strHead.AppendFormat("HouseAddress:{{width:{0},head:'{1}',sortable:true,style:'text-align:left'}},", 170, "客户姓名");
        }
        else
        {
            strHead.AppendFormat("HouseAddress:{{width:{0},head:'{1}',sortable:true,style:'text-align:left'}},", 170, "房源地址");
        }
        
        strHead.AppendFormat("TraceTime:{{width:{0},head:'{1}',sortable:true}},", 70, "跟单时间");
        strHead.AppendFormat("Tractor:{{width:{0},head:'{1}',sortable:true}},", 60, "跟单人");
        strHead.AppendFormat("Depart:{{width:{0},head:'{1}',sortable:true}},", 80, "跟单部门");
        strHead.AppendFormat("TraceContext:{{width:{0},head:'{1}',sortable:true,style:'text-align:left'}},", 600, "跟单内容");

        strHtml.Append("{");
        strHtml.Append("success:'1',");
        strHtml.Append("msg:'',");
        strHtml.AppendFormat("data:{{{0},", Chenxin.Lib.Utility.JsonHelp.Convert2Json(dsList.Tables[0]));
        strHtml.AppendFormat("head:{{{0}}}", strHead.ToString());
        strHtml.AppendFormat(",count:'{0}'", dsList.Tables[1].Rows[0][0]);
        strHtml.Append("}");
        strHtml.Append("}");

        return strHtml.ToString();
    }
    
    
}